package com.sharding.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

@Slf4j
public class TableShardingAlgorithm implements PreciseShardingAlgorithm<String> {

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<String> preciseShardingValue) {
        try{
            log.info("preciseShardingValue:{},column:{}",preciseShardingValue.getValue(),preciseShardingValue.getColumnName());
            for (String each : availableTargetNames) {
                log.info("each:" + each);
            }
            return "s_user0";
        } catch (Exception e){
            e.printStackTrace();
        }
        throw new IllegalArgumentException();
    }
}
